package com.lau.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by liutf on 2016/7/19.
 */
public class UserDynProxy implements InvocationHandler{

    Object target;

    public Object bind(Object target){
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("start transaction ..");
        Object result = method.invoke(target, args);
        System.out.println("commit transaction ..");
        return result;
    }

}
